Imports System.Data.SqlClient

Friend Class DBTableSize
    Inherits DBBase

    Public Sub New()
        MyBase.New()
    End Sub

    Public Sub Load( _
            ByRef oObject As SQLAutoDocLib.TableSize)

        Dim sSQL As String = "select"
        sSQL = sSQL & "     [Session],"
        sSQL = sSQL & "     [TableID],"
        sSQL = sSQL & "     [TableRevID],"
        sSQL = sSQL & "     [RowCount],"
        sSQL = sSQL & "     [Reserved],"
        sSQL = sSQL & "     [Data],"
        sSQL = sSQL & "     [Index_Size],"
        sSQL = sSQL & "     [Unused],"
        sSQL = sSQL & "     [CreateDate]"
        sSQL = sSQL & " from"
        sSQL = sSQL & "     TableSizeHistory"
        sSQL = sSQL & " where"
        sSQL = sSQL & "     [ID]=" & oObject.ID

        Dim oData As DataTable = MyBase.ExecuteReadToDataTable(sSQL)

        If oData.Rows.Count > 0 Then
            With oData.Rows(0)
                oObject.SessionID = .Item("Session")
                oObject.TableID = .Item("TableID")
                oObject.TableRevID = .Item("TableRevID")
                oObject.RowCount = .Item("RowCount")
                oObject.Reserved = .Item("Reserved")
                oObject.Data = .Item("Data")
                oObject.Index_Size = .Item("Index_Size")
                oObject.Unused = .Item("Unused")
                oObject.CreateDate = .Item("CreateDate")
            End With
        End If

        oData.Dispose()
    End Sub

    Public Sub Add(ByRef oObject As SQLAutoDocLib.TableSize)

        Dim sSQL As String = "insert into TableSizeHistory ("
        sSQL = sSQL & "     [ID],"
        sSQL = sSQL & "     [Session],"
        sSQL = sSQL & "     [TableID],"
        sSQL = sSQL & "     [TableRevID],"
        sSQL = sSQL & "     [RowCount],"
        sSQL = sSQL & "     [Reserved],"
        sSQL = sSQL & "     [Data],"

        sSQL = sSQL & "     [Index_Size],"
        sSQL = sSQL & "     [Unused],"
        sSQL = sSQL & "     [CreateDate]) values ("

        sSQL = sSQL & ValueToDBValue(oObject.ID) & ","
        sSQL = sSQL & ValueToDBValue(oObject.SessionID) & ","
        sSQL = sSQL & ValueToDBValue(oObject.TableID) & ","
        sSQL = sSQL & ValueToDBValue(oObject.TableRevID) & ","
        sSQL = sSQL & ValueToDBValue(oObject.RowCount) & ","
        sSQL = sSQL & ValueToDBValue(oObject.Reserved) & ","
        sSQL = sSQL & ValueToDBValue(oObject.Data) & ","
        sSQL = sSQL & BooleanToBit(oObject.Index_Size) & ","
        sSQL = sSQL & ValueToDBValue(oObject.Unused) & ","
        sSQL = sSQL & ValueToDBValue(oObject.CreateDate) & ")"

        MyBase.ExecuteNonQuery(sSQL)
    End Sub

    Public Sub Delete(ByRef oObject As SQLAutoDocLib.TableSize)
        Dim sSQL As String = "delete from TableSizeHistory"
        sSQL = sSQL & " where"
        sSQL = sSQL & "     [ID]=" & oObject.ID

        MyBase.ExecuteNonQuery(sSQL)
    End Sub
End Class
